package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {

	http.HandleFunc("/upload", upload)
	err := http.ListenAndServe("127.0.0.1:9090", nil) //设置监听的端口
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

func upload(w http.ResponseWriter, r *http.Request) {

	get := r.URL.Query()

	if v, ok := get["id"]; ok {
		if len(v) != 1 || v[0] == "" {
			fmt.Println("xxxx", v)
		}
	}

	fmt.Println(r.URL.Query())

	fmt.Println(r.Method) //GET

	//这个很重要,必须写
	r.ParseForm()

	id := r.Form.Get("id")
	filename := r.Form.Get("filename")

	fmt.Println(id, filename) // 1 test.zip

	//第二种方式,底层是r.Form
	id2 := r.FormValue("id")
	filename2 := r.FormValue("filename")
	fmt.Println(id2, filename2) // 1 test.zip

}
